﻿using System;
using SchemaGen.Xsd;

namespace SchemaGen.Attributes
{
    [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
    public sealed class XmlDocumentAttribute : Attribute
    {
        public string RootElementName { get; private set; }
        public Uri BaseNamespace { get; private set; }
        public Type[] IncludedTypes { get; private set; }
        public string FileName { get; set; }
        public Uri LocalNamespace { get; set; }
        public SequenceIndicator SequenceIndicator { get; set; }
        public string Namespace { get { return BaseNamespace.AbsoluteUri + '/' + LocalNamespace; } }

        public XmlDocumentAttribute(string rootElementName, string baseNamespace, params Type[] includedTypes)
        {
            RootElementName = rootElementName;
            IncludedTypes = includedTypes ?? new Type[] { };
            BaseNamespace = new Uri(baseNamespace, UriKind.Absolute);
            LocalNamespace = new Uri(rootElementName + ".xsd", UriKind.Relative);

            FileName = string.Format("{0}.{1}.{2}",
                BaseNamespace.LocalPath.TrimStart('/').TrimEnd('/').Replace('/', '.'),
                rootElementName,
                "xsd");

            SequenceIndicator = Xsd.SequenceIndicator.Sequence;
        }
    }
}
